<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<title>Index</title>
</head>
<body>Index page! ${message} ${time}

<a href="${ctx}/testjson">测试json数据发送啊啊</a>

</body>
<script type="text/javascript" src="${ctx}/static/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
var list=[{id:1,name:"zhangsan"},{id:2,name:"lishi"}];

var list0 = {id:1,name:"zzzz"};
$(function(){
	
	console.info(JSON.stringify({list:list}));
	
	var jsonparam = JSON.stringify(list);
	
	var param2 = JSON.stringify(list0);
	
	console.info(jsonparam);
	console.info(param2);
	
	var data=[];
	
	$(list).each(function(i,n){
		data.push("list[" + i + "].id=" + n.id);
		data.push("list[" + i + "].name=" + n.name);
	});
	
	data = data.join("&");
	
	//console.info(data);
	
	$.ajax({
		type : "GET",
	    contentType : 'application/json;charset=utf-8', //设置请求头信息
		async:false,
		url : "${ctx}/callback",
		dataType : "jsonp",
		data:data,
		jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)
		 jsonpCallback:"flightHandler",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名，也可以写"?"，jQuery会自动为你处理数据
		success : function(data) {
			console.info(data);
			console.info(data[0].id);
			console.info(data[0].name);
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert("获取错误");
		}
	});
	
	//替换a链接
	
	var $a = $("a:first");
	//console.info($a);
	
	$a.attr("href",$a.attr("href") + "?param=" + jsonparam);
	
	console.info($a.attr("href"));
	
});
</script>
</html>